package br.com.simora.crawler;

import javax.inject.Named;

import org.apache.log4j.Logger;

import br.com.simora.musica.Artista;
import br.com.simora.musica.Musica;
import br.com.simora.radio.RadioEnum;

@Named("litefm")
public class LiteFMCrawler extends AbstractCrawler {
	private static Logger logger = Logger.getLogger(LiteFMCrawler.class);
	private static String URL = "http://aovivo.visar.com.br/playerinfo2/antena1_noar.html";
	private static String INFOS = "//div[@class='txt_nm']/text()";
	
	@Override
	public void recuperaInfo(){
		recuperador.setUrl(URL, "html");
		String itensConteudo = "";
		String artistaNome = "";
		String musicaNome = "";
		try {
			itensConteudo = recuperador.recuperaItem(INFOS);
		} catch (Exception e) {
			logger.debug(e.getMessage());
			e.printStackTrace();
		}
		if(!"".equals(itensConteudo) && null != itensConteudo){
			if(itensConteudo.contains(":")){
				itensConteudo = itensConteudo.split(":")[1];
			}
			String[] itens = itensConteudo.split("-");
			if(itens.length > 0){
				if(itens[0] != null){
					artista = new Artista();
					artistaNome = itens[0].trim();
					artista.setNome(artistaNome);
				}
				if(itens[1] != null){
					musica = new Musica();
					musicaNome = itens[1].trim();
					musica.setNome(musicaNome);
				}
			}
		}
		logger.debug(artistaNome + " - " + musicaNome);
	}

	@Override
	public void setRadioNome() {
		this.radioNome = RadioEnum.litefm.getNome();
	}

}